package com.example.monitor.model.DO;

import com.example.monitor.model.enums.Role;
import com.example.monitor.model.enums.UserStatus;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.UpdateTimestamp;

import jakarta.persistence.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Collections;
import java.util.Date;

@Data
@Entity
@Table(name = "users")
public class User implements UserDetails {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "user_id")
    private Long userId;

    @Column(unique = true, nullable = false, length = 50)
    private String username;

    @Column(nullable = false, length = 100)
    private String passwordHash;

    @Column(length = 20)
    private String phone;

    @Column(length = 100)
    private String email;

    // ============== UserDetails 接口方法 ==============
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return Collections.emptyList(); // 若无角色权限，返回空列表
    }

    @Override
    public String getPassword() {
        return this.passwordHash; // 必须实现
    }

    @Override
    public String getUsername() {
        return this.username; // 必须实现
    }

    @Override
    public boolean isAccountNonExpired() {
        return true; // 账户是否未过期（默认true）
    }

    @Override
    public boolean isAccountNonLocked() {
        return true; // 账户是否未锁定（默认true）
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true; // 凭证是否未过期（默认true）
    }

    @Override
    public boolean isEnabled() {
        return true; // 账户是否启用（默认true）
    }

}